﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using AutumnEngine.Modules;
using System.Diagnostics;
using AutumnEngine;

namespace AutumnEngine.Modules
{
    /// <summary>
    /// Manages textures and provides a central repository to access them.
    /// </summary>
    public class TextureManagerModule : Module
    {
        Dictionary<string, Texture2D> textures = new Dictionary<string, Texture2D>();
        Dictionary<string, string> texturePaths = new Dictionary<string, string>();

        /// <summary>
        /// Adds the texture.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="path">The path.</param>
        public void AddTexture(string name, string path)
        {
            if (Engine.Modules.Contains("Engine.Logging"))
                Engine.Modules.Logging.Write("Adding texture " + name, LogLevel.Debug);
            try
            {
                texturePaths.Add(name, path);
                textures.Add(name, Engine.Modules.ContentManager.Load<Texture2D>(path));
            }
            catch (Exception) { }
        }

        /// <summary>
        /// Gets the texture.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        public Texture2D GetTexture(string name)
        {
            return textures[name];
        }

        public string TexturePathFromKey(string key)
        {
            return texturePaths[key];
        }

        /// <summary>
        /// Creates this instance.
        /// </summary>
        public override void Create()
        {
            this.Removable = false;
            this.CanBeDisabled = false;
            base.Create();
        }
    }
}
